package com.qf.controller;
import com.qf.entity.Doctor;
import com.qf.entity.YuYue;
import com.qf.pojo.BaseResult;
import com.qf.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@CrossOrigin
@RequestMapping("/doctor")
public class DoctorController {

    @Autowired
    DoctorService doctorService;

    //医生登录
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public BaseResult login(@RequestBody Doctor doctor){
        BaseResult baseResult = doctorService.login(doctor);
        return baseResult;
    }

    //医生根据权限展示自己的页面
    @RequestMapping(value ="/findByIdCard/{idCard}", method = RequestMethod.GET)
    public BaseResult findByIdCard(@PathVariable Integer idCard){
        BaseResult baseResult = doctorService.findByIdCard(idCard);
        return baseResult;
    }

    //医生查看个人资料
    @RequestMapping(value="/showInfoByIdCard/{idCard}",method = RequestMethod.GET)
    public BaseResult showInfoByIdCard (@PathVariable Integer idCard){
        BaseResult baseResult = doctorService.showInfoByIdCard(idCard);
        return baseResult;
    }

    //医生修改个人资料
    @RequestMapping(value = "/changeInfoByIdCard",method = RequestMethod.PUT)
    public BaseResult changeInfoByIdCard(@RequestBody Doctor doctor){
        System.out.println(doctor+"==========");
        BaseResult baseResult = doctorService.changeInfoByIdCard(doctor);
        return baseResult;
    }

    /**
     * 根据医生id查询该医生下当前已预约的患者信息
     *
     * @return
     */
    @GetMapping("/findById/{id}")
    public BaseResult findById(@PathVariable("id") Integer id) {
        try {
            List<YuYue> patientList = doctorService.findById(id);
            return new BaseResult(1, "查询成功!!!", patientList);
        } catch (Exception e) {
            e.printStackTrace();
            return new BaseResult(0, "查询失败!!!", null);
        }
    }

    @RequestMapping("/updateByNum/{num}")
    public BaseResult updateByNum(@PathVariable String num){
        try {
            doctorService.updateByNum(num);
            return new BaseResult(1,"修改成功!",null);
        } catch (Exception e) {
            e.printStackTrace();
            return new BaseResult(0,"修改失败!",null);
        }
    }
}
